// JavaScript Document
// --- 获取ClassName
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var j = 0; j < elem.length; j++) {
var classes = elem[j].className;
if (myclass.test(classes)) retnode.push(elem[j]);
}
return retnode;
}
// --- 隐藏所有
function HideAll() {
var items = document.getElementsByClassName("optiton");
for (var j=0; j<items.length; j++) {
items[j].style.display = "none";
}
}
// --- 设置cookie
function setCookie(sName,sValue,expireHours) {
var cookieString = sName + "=" + escape(sValue);
//;判断是否设置过期时间
if (expireHours>0) {
 var date = new Date();
 date.setTime(date.getTime + expireHours * 3600 * 1000);
 cookieString = cookieString + "; expire=" + date.toGMTString();
}
document.cookie = cookieString;
}
//--- 获取cookie
function getCookie(sName) {
  var aCookie = document.cookie.split("; ");
  for (var j=0; j < aCookie.length; j++){
var aCrumb = aCookie[j].split("=");
if (escape(sName) == aCrumb[0])
  return unescape(aCrumb[1]);
  }
  return null;
}
window.onload = function() {
var show_item = "opt_1";
if (getCookie("show_item") != null) {
 show_item= "opt_" + getCookie("show_item");
 if(show_item!="opt_1")
 HideClassValue(getCookie("show_item"));
}

if(document.getElementById(show_item)!=null&&document.getElementById(show_item)!='null')
document.getElementById(show_item).style.display = "block";
var items = document.getElementsByClassName("title");
for (var j=0; j<items.length; j++) {
items[j].onclick = function() {
HideClassValue(this.name);

//document.getElementById("li_" + this.name).className="item active";
var o = document.getElementById("opt_" + this.name);
if (o.style.display != "block") {
HideAll();

o.style.display = "block";
setCookie("show_item",this.name);
}
else {
o.style.display = "none";
}

ActiveTitle(this.name);
}

}

showsubmenu(1);

}
function HideClassValue(id)
{
  for(var i=1;i<=meunCount;i++)
  {
	  if(i!=id)
		  document.getElementById("li_" + i).className="item default";
  }
  try{
	  if(document.getElementById("li_" + id).className=="item active")
		  document.getElementById("li_" + id).className="item default";
	  else
		  document.getElementById("li_" + id).className="item active";
  }catch(e){
	  
  }
}

function ActiveTitle(n)
{
  for(var i=1;i<=meunCount;i++)
  {
    document.getElementById("a" + i).className="titleUnActive";
  }
  document.getElementById("a" + n).className="titleActive";
}

function showsubmenu(sid,k) {
	whichEl = eval(document.getElementById("tt" + sid));
	var hidVal = document.getElementById("MenuBottom").value;
	var fId = "," + sid;
	if (whichEl != null && whichEl != 'null') {
		if (whichEl.style.display != 'block') { // 关闭状态 就展开
			document.getElementById("tt" + sid).style.display = "block";
			document.getElementById("t" + sid).className = "minus";
			if (hidVal.indexOf(fId) != -1)
				document.getElementById("t" + sid).className = "minusBottom";
			
			//zsl 20130118新增点击另一个菜单 其他菜单关闭  menu.do新增传递k参数  
			//start 
			var lis=document.getElementById("opt_"+k).getElementsByTagName("li"); //获取改菜单下所有li信息
			var j=0; 
			var arr=new Array();//二级菜单 控制li的id数组
			if(lis!=null && lis.length>0){
				for(var i=0;i<lis.length;i++){ 
					for(var m=0;m<lis.length;m++){ 
						if(lis[i].id!=null && lis[i].id!="" && lis[i].id=="t"+m){ //获取拥有子二级菜单个数
							arr[j]="tt"+m;
							j++;
						}
					}
				}
			} 
			if(arr!=null && arr.length>0){
				for(var i=0;i<arr.length;i++){ 
					if("tt"+sid!=arr[i]){//不为当前选择的关闭
						document.getElementById(arr[i]).style.display = "none";  
					}
				}
			}
			//end
			
		} else {
			document.getElementById("tt" + sid).style.display = "none";
			document.getElementById("t" + sid).className = "plus";
			if (hidVal.indexOf(fId) != -1)
				document.getElementById("t" + sid).className = "plusBottom";
		}
	}
}